﻿using MediatR;
using WarehouseManagement.Application.Command.WarehouseTypeCommand;
using WarehouseManagement.Domain.DTO.WarehouseType;
using WarehouseManagement.Infrstructre.Interface;
namespace WarehouseManagement.Application.CommandHandler.WareTypeCommandHandler
{
    /// <summary>
    /// 仓库分类反填
    /// </summary>
    public class FillWareTypeCommandHandler:IRequestHandler<FillWareTypeCommand, UptWareHouseTypeDto>
    {

        private  readonly IWareTypeRepository _wareTypeRepository;

        public FillWareTypeCommandHandler(IWareTypeRepository wareTypeRepository)
        {
            _wareTypeRepository = wareTypeRepository;
        }

        public async Task<UptWareHouseTypeDto> Handle(FillWareTypeCommand request, CancellationToken cancellationToken)
        {
            var result = (await _wareTypeRepository.GetAll())
               .Where(x => x.WarehouseCategoryId == request.Wid)
               .ToList();
            var dto = result.Select(x => new UptWareHouseTypeDto
            {
                WarehouseCategoryId = x.WarehouseCategoryId,
                WarehouseId = x.WarehouseId,
                WCFatherType = x.WCFatherType,
                WCTypeName = x.WCTypeName,
                AddName = x.AddName,
                AddTime = x.AddTime,
                WCTypeNumber = x.WCTypeNumber,
                DelTime = x.DelTime,
                DelName = x.DelName,
                Office_Id = x.Office_Id,
                User_Id = x.User_Id,
                UpdName = x.UpdName,
                UpdTime = x.UpdTime

            }).FirstOrDefault();
            return dto;
        }
    }
}
